#e
#Title[zNu͕Ɓv]
#Text[]
#Image[]
#BackGround[]
#BGM[]
#PlayLevel[Extra]
#ScriptVersion[2]
#Player[FREE]


script_enemy_main
{

	//GoɈxs镔
	@Initialize
	{
	//   eϐ

	//   XyJ[hf[^
	SetLife(1000);
	SetScore(300000);
	SetDamageRate(0,  0);
	SetTimer(87);
	SetInvincibility(250);
	SetDurableSpellCard();
	SetEnemyMarker(false);
	LoadGraphic("script\img\ExRumia.png");
	CutIn(KOUMA,"zNu͕Ɓv",GetCurrentScriptDirectory~"..\img\cutin09.png",0,0,255,320);
	}
	//   ʒu܂ňړ
	SetMovePosition02(GetCenterX, GetCenterY-140, 60);

	BG_Standard;
	AtackTaskA;
	AtackTaskB;
	MoveTask;

	//G̃Ct0ɂȂ܂ŁA̕1t[1s
	@MainLoop
	{
		yield;



	}
	
	//`惋[vB1t[1s
	@DrawLoop
	{
		SetGraphicRect(0,1,63,64);
		if(GetSpeedX<0){
			SetGraphicRect(128,1,191,64);
		}
		if(GetSpeedX>0){
			SetGraphicRect(192,1,255,64);
		}		SetColor(255,255,255);
		SetAlpha(96);
		SetTexture("script\img\ExRumia.png");//摜͔q
		DrawGraphic(GetX,GetY);
	}
		
	//GłuԂɈxs镔
	@Finalize
	{
		DeleteGraphic("script\img\ExRumia.png");
		DeleteGraphic(GetCurrentScriptDirectory ~"..img\back1.png");
		DeleteGraphic(GetCurrentScriptDirectory ~"..img\back2.png");
	}
	//XyJ[h̔wi
	//Ă悢
	@BackGround
	{
		BG_Simple;
	}

	task AtackTaskA{
		wait(180);

		//̏H
		loop(12){
			CreateLaser01(GetX+30,GetY,6,90,120,20,BLUE01,1);
			CreateLaser01(GetX+10,GetY+40,6,90,120,20,BLUE01,1);
			CreateLaser01(GetX-10,GetY+40,6,90,120,20,BLUE01,1);
			CreateLaser01(GetX-30,GetY,6,90,120,20,BLUE01,1);
			wait(30);
		}

		//̔˃[U[H
		CreateLaserA(0,GetClipMinX,GetClipMinY,800,40,BLUE01,30);
		SetLaserDataA(0,0,90,0,0,0,0);
		SetLaserDataA(0,30,NULL,0,0,2,0);
		SetLaserDataA(0,75,NULL,0,0,0,0);
		SetShotKillTime(0,320);
		FireShot(0);
		CreateLaserA(0,GetClipMaxX,GetClipMinY,800,40,BLUE01,30);
		SetLaserDataA(0,0,90,0,0,0,0);
		SetLaserDataA(0,30,NULL,0,0,-2,0);
		SetLaserDataA(0,75,NULL,0,0,0,0);
		SetShotKillTime(0,320);
		FireShot(0);
		wait(60);
		CreateLaserC(0,GetX,GetY,20,60,BLUE01,20);
		CreateLaserC(1,GetX,GetY,20,60,BLUE01,20);
		SetLaserDataC(0,0,7.5,15,0,0,0);
		SetLaserDataC(1,0,7.5,165,0,0,0);
		let frame=15;
		loop(5){
			SetLaserDataC(0,frame,NULL,165,0,0,0);
			SetLaserDataC(1,frame,NULL,15,0,0,0);
			frame+=30;
			SetLaserDataC(0,frame,NULL,15,0,0,0);
			SetLaserDataC(1,frame,NULL,165,0,0,0);
			frame+=30;
		}
		FireShot(0);
		FireShot(1);

		//̃PbgˁH
		wait(280);
		CreateLaserB(0,300,60,ORANGE01,30);
		SetLaserDataB(0,0,0,80,0,45,0,90,0);
		SetShotKillTime(0,360);
		FireShot(0);
		CreateLaserB(0,300,60,ORANGE01,30);
		SetLaserDataB(0,0,0,80,0,135,0,90,0);
		SetShotKillTime(0,360);
		FireShot(0);
		wait(360);

		//ȍUp^[CH
		let dir=rand(0,360);
		loop(10){
			loop(8){
				CreateShot01(GetX,GetY,6,dir,RED02,20);
				dir+=45;
			}
			wait(10);
			dir+=12;
		}
		loop(10){
			loop(8){
				CreateShot01(GetX,GetY,6,dir,RED02,20);
				dir+=45;
			}
			wait(10);
			dir-=12;
		}
		wait(80);

		//ăC_[H
		let ldir=0;
		let rdir=0;
		let rot=0;
		let rotangle=0;
		ascent(i in 0..79){
			alternative(i)
			case(20,60){
				if(GetX>GetPlayerX){rotangle=-2;}
				else{rotangle=2;}
			}
			case(40,120){
				rotangle=0;
			}
			case(0){
				ldir=atan2(GetPlayerY-GetY,GetPlayerX-(GetX-40))-36;
				rdir=atan2(GetPlayerY-GetY,GetPlayerX-(GetX+40))-60;
			}

			loop(5){
				CreateShot01(GetX-40,GetY,10,ldir+rot,ORANGE23,10);
				CreateShot01(GetX+40,GetY,10,rdir+rot,ORANGE23,10);
				ldir+=24;
				rdir+=24;
			}
			ldir-=120;
			rdir-=120;
			rot+=rotangle;

			wait(3);
		}
		wait(60);

		//̃C_[H
		let dir=GetAngleToPlayer+10;
		rotangle=0;
		rot=-2;
		ascent(i in 0..120){
			alternative(i)
			case(20){
				rotangle=-0.2;
			}
			case(56){
				rotangle=0;
			}
			loop(16){
				CreateShot01(GetX,GetY,10,dir+rot,ORANGE23,10);
				CreateShot01(GetX,GetY,10,dir-rot,ORANGE23,10);
				dir+=360/16;
			}
			rot+=rotangle;
			wait(3);
		}

		//̃VbgKH
		wait(60);
		let wt=100;
		loop(2){
			loop(2){
				SG_Set(GetX-60,GetY-30);
				wait(wt);
				SG_Set(GetX+60,GetY-30);
				wait(wt);
				SG_Set(GetX-120,GetY-30);
				wait(wt);
				SG_Set(GetX+120,GetY-30);
				wait(wt);
			}
			wait(60);
			wt=30;
		}
		wait(120);
		DeleteEnemyShot(SHOT);


		//̃rbgUH
		let interval=3;
		let fire=8;
		let sleep=4;
		loop(2){
			CrossCannon(GetClipMinX+80,GetClipMinY+40,2,2,90,270,200,interval,fire,sleep,YELLOW03,RED23,30,10);
			wait(60);
			CrossCannon(GetClipMinX+80,GetClipMinY+40,2,2,0,180,150,interval,fire,sleep,YELLOW03,RED23,30,10);
			wait(60);
			CrossCannon(GetClipMaxX-80,GetClipMinY+40,2,2,90,270,200,interval,fire,sleep,YELLOW03,RED23,30,10);
			wait(60);
			CrossCannon(GetClipMaxX-80,GetClipMinY+40,2,2,180,0,150,interval,fire,sleep,YELLOW03,RED23,30,10);
			wait(60);
		}
		wait(480);

		//̍ŏI`ԁH
		FinalAtack;
		wait(120);
		Slow(2);
		wait(620);
		Slow(0);

	}
	task MoveTask{
		wait(180);
		loop(12){
			if(GetX<GetPlayerX){
				SetMovePosition02(limit(GetX+100,GetClipMinX+40,GetClipMaxX-40), GetY, 29);
			}
			else{
				SetMovePosition02(limit(GetX-100,GetClipMinX+40,GetClipMaxX-40), GetY, 29);
			}
			wait(30);
		}
		SetMovePosition02(GetCenterX, rand(80,120), 30);
		wait(300);
		SetMovePosition03(GetCenterX, GetClipMaxY-140,30, 8);
		wait(120);
		if(GetX>GetPlayerX){
			SetMovePosition02(GetCenterX-20, GetY, 30);
			wait(30);
			SetMovePosition03(GetClipMinX+60, GetY,30, 1.5);
		}
		else{
			SetMovePosition02(GetCenterX+20, GetY, 30);
			wait(30);
			SetMovePosition03(GetClipMaxX-60, GetY,30, 1.5);
		}
		wait(120);
		SetMovePosition03(GetX, 100,30, 2);
		wait(120);
		SetMovePosition01(GetCenterX,GetY,0.5);
		wait(260);
		wait(240);
		SetSpeed(0.2);
		loop(4){
			SetAngle(GetAngleToPlayer-90);
			wait(60);
			SetAngle(GetAngleToPlayer+90);
			wait(60);
		}
		SetMovePosition02(GetCenterX, GetCenterY-140, 60);

	}

	task SG_Set(	//VbgKA܂Ƃ߁B
		x,y
	){
		ascent(i in -1..2){
			CreateShot01(x,y,6,i*3+atan2(GetPlayerY-y,GetPlayerX-x),RED03,30);
		}
		ShotGun(x,y,0.5,5.5,atan2(GetPlayerY-y,GetPlayerX-x),20,16,RED02,30);
		ShotGun(x,y,0.5,2,atan2(GetPlayerY-y,GetPlayerX-x),40,16,RED02,30);
	}
	task ShotGun(		//̃VbgK
		x,
		y,
		spdmin,
		spdmax,
		dirbase,
		dirmax,
		ammo,
		grf,
		delay
	){
		loop(ammo){
			CreateShot01(x,y,rand(spdmin,spdmax),rand(-dirmax,dirmax)+dirbase,grf,delay);
		}
	}

	task CrossCannon(	//̃rbg
		x,
		y,
		spda,		//eȇx
		spdb,		//qȇx
		dira,		//
		dirb,		//]
		change,		//]t[
		interval,	//UԊu
		fire,		//U^[
		sleep,		//x^[
		grfa,
		grfb,
		delaya,
		delayb
	){
		let obj=Obj_Create(OBJ_SHOT);
		Obj_SetPosition(obj,x,y);
		Obj_SetSpeed(obj,spda);
		Obj_SetAngle(obj,dira);
		ObjShot_SetBombResist(obj,true);
		ObjShot_SetDelay(obj,delaya);
		ObjShot_SetGraphic(obj,grfa);
		wait(delaya);
		let dir=0;
		let frame=0;
		let count=fire;
		while(!Obj_BeDeleted(obj)){
			if(frame==change){
				Obj_SetAngle(obj,dirb);
			}
			if(frame%interval==0){
				if(count>0){
					loop(4){
						CreateShot01(Obj_GetX(obj),Obj_GetY(obj),spdb,dir,grfb,delayb);
						dir+=90;
					}
					count--;
				}
				if(count<-1){count++;}
				if(count==0){count=-sleep-1;}
				if(count==-1){count=fire;}
			}
			yield;
			frame++;
		}
	}
	task FinalAtack{	//̍U(v)
		let dir=90;
		let dirb=90;
		let x=GetCenterX;
		let y=GetCenterY-80;
		let nway=24;
		let spd=3;
		let side=45;
		descent(i in 40..120){
			loop(nway){
				//y=GetCenterY-i;
				let cx=cos(dir)*i;
				let cy=sin(dir)*i/3;
				CreateShot01(cx+x,cy+y,spd,dir+180,PURPLE04,30);
				CreateShot01(cx+x,cy+y,spd,dir+180-side,PURPLE05,30);
				CreateShot01(cx+x,cy+y,spd,dir+180+side,PURPLE05,30);
				dir+=360/nway;
			}
			wait(8);
			dir+=5.678;
		}
	}


	task AtackTaskB{	//{oA펞WJ
		Concentration01(120);
		wait(120);
		let dirx=0;
		let diry=45;
		let dirz=60;
		let distance=100;
		let expand=1;
		let laserwidth=8;
		let vertex=7;
		let rotx=2.2;
		let roty=1.0;
		let rotz=0.3;
		let separate=vertex;
		let delay=40;
		let color=[WHITE01,PURPLE01,RED01,BLUE01,GREEN01,YELLOW01,ORANGE01];

		ascent(i in 0..length(color)){
			loop(vertex){
				LaserRing(dirx,diry+(180/length(color)*i),dirz+(360/length(color)*i),rotx,roty,rotz,distance,expand,laserwidth,-1,separate,vertex,color[i],delay);
				dirx+=360/vertex;
			}
			separate+=vertex;

		}
	}


	#include_function".\function.txt"
}

